package com.xintai.system.controller;

import java.util.List;

import com.xintai.utils.StaticString;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.ErpCaizhi;
import com.xintai.system.service.IErpCaizhiService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 热卷材质Controller
 * 
 * @author xintai
 * @date 2021-01-15
 */
@RestController
@RequestMapping("/system/caizhi")
public class ErpCaizhiController extends BaseController
{
    @Autowired
    private IErpCaizhiService erpCaizhiService;

    /**
     * 查询热卷材质列表
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpCaizhi erpCaizhi)
    {
        startPage();
        List<ErpCaizhi> list = erpCaizhiService.selectErpCaizhiList(erpCaizhi);
        return getDataTable(list);
    }

    /**
     * 导出热卷材质列表
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:export')")
    @Log(title = "热卷材质", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpCaizhi erpCaizhi)
    {
        List<ErpCaizhi> list = erpCaizhiService.selectErpCaizhiList(erpCaizhi);
        ExcelUtil<ErpCaizhi> util = new ExcelUtil<ErpCaizhi>(ErpCaizhi.class);
        return util.exportExcel(list, "caizhi");
    }

    /**
     * 获取热卷材质详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:query')")
    @GetMapping(value = "/{czId}")
    public AjaxResult getInfo(@PathVariable("czId") Long czId)
    {
        return AjaxResult.success(erpCaizhiService.selectErpCaizhiById(czId));
    }

    /**
     * 新增热卷材质
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:add')")
    @Log(title = "热卷材质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpCaizhi erpCaizhi)
    {
        if (erpCaizhiService.verifyCaiZhi(erpCaizhi))
            return AjaxResult.error(StaticString.NameRepeat(erpCaizhi.getCzName()));
        return toAjax(erpCaizhiService.insertErpCaizhi(erpCaizhi));
    }

    /**
     * 修改热卷材质
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:edit')")
    @Log(title = "热卷材质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpCaizhi erpCaizhi)
    {
        if (erpCaizhiService.verifyCaiZhi(erpCaizhi))
            return AjaxResult.error(StaticString.NameRepeat(erpCaizhi.getCzName()));
        return toAjax(erpCaizhiService.updateErpCaizhi(erpCaizhi));
    }

    /**
     * 删除热卷材质
     */
    @PreAuthorize("@ss.hasPermi('system:caizhi:remove')")
    @Log(title = "热卷材质", businessType = BusinessType.DELETE)
	@DeleteMapping("/{czIds}")
    public AjaxResult remove(@PathVariable Long[] czIds)
    {
        return toAjax(erpCaizhiService.deleteErpCaizhiByIds(czIds));
    }
}
